package pro.softzhang.algo.lc1000;

import pro.softzhang.algo.flag.knowledge.KSlidingWindow;

public class LC1493_LongestSubarrayOf1sAfterDeletingOneElement {
    public static void main(String[] args) {

    }

    @KSlidingWindow
    static
    class Solution {
        public int longestSubarray(int[] nums) {
            int longest = 0;
            for(int lp = 0, rp = 0, zeros = 0; rp < nums.length; rp++) {
                if(nums[rp] == 0) {
                    zeros++;
                }
                while (zeros > 1) {
                    if(nums[lp++] == 0) {
                        zeros--;
                    }
                }
                longest = Math.max(longest, rp - lp);
            }
            return longest;
        }
    }
}
